export const permsMap = {
  // '查看': ['use-pic-switch', 'use-scale', 'use-drag-body'],
  '查看': [],
  '标注': ['use-layer', 'use-task'],
  '审核': ['use-comment', 'use-judge'],
};

export function UserOp() {
  return localStorage.getItem('operate') || '查看';
}
export const UserEq = op => R.equals(UserOp(), op);

export const OpIdx = op => Object.keys(permsMap).indexOf(op);
export const UserOpIdx = R.compose(OpIdx, UserOp);
export const UserOpGte = op => R.compose(R.gte(UserOpIdx()), OpIdx)(op);

export function useOpPerms() {
  const Filenames = R.compose(R.unnest, lv => R.slice(0, lv, R.values(permsMap)), R.inc, UserOpIdx);

  Promise
  .all(Filenames().map(filename => import(`./api/${ filename }.js`)))
  .then(modules => modules.forEach(module => module.default()));
}
